package com.chen.controller;

import com.chen.service.CoachService;
import com.chen.service.CourseService;
import com.chen.vo.Result;
import com.chen.vo.param.CourseParam;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author:chenao
 * @DATE:2022/3/11 22:22
 */
@RestController
@RequestMapping("course")
public class CourseController {

    @Autowired
    private CourseService courseService;
    @Autowired
    private CoachService coachService;

    /**
     * 添加或编辑课程
     * @param file
     * @param params
     * @return
     */
    @PostMapping("save")
    public Result saveCourse(@RequestParam("file") MultipartFile file, @RequestParam Map<String,String> params){
        return courseService.saveCourse(file,params);
    }

    /**
     * 课程列表
     * @param params
     * @return
     */
    @PostMapping("list")
    public Result listCourse(@RequestBody CourseParam params){
        return courseService.listCourse(params);
    }

    /**
     * 用于选择教练时展示教练名字，下拉列表
     * @return
     */
    @PostMapping("coachlist")
    public Result listCoachName(){
        return coachService.listCoachName();
    }

    /**
     * 通过id删除课程
     * @param params
     * @return
     */
    @PostMapping("delete")
    public Result delete(@RequestBody CourseParam params){
        return courseService.deleteById(params.getId());
    }

    /**
     * 课程数量统计1-12月
     * @return
     */
    @PostMapping("statistic")
    public Result courseStatistic(){
        return courseService.statistic();
    }

    @PostMapping("reserve/statistic")
    public Result recordStatis(){
        return courseService.reserveStatis();
    }
}
